using Godot;
using System;

public partial class PauseMenu : Control
{
	private CenterContainer crosshair;
	private VBoxContainer pause;
	private Options options;
	private VoxelWorld voxel_world;

	public override void _Ready()
	{
		crosshair = GetNode<CenterContainer>("Crosshair");
		pause = GetNode<VBoxContainer>("Pause");
		options = GetNode<Options>("Options");
		voxel_world = GetNode<VoxelWorld>("../VoxelWorld");
	}

	public override void _Process(double delta)
	{
		if (Input.IsActionJustPressed("pause"))
		{
			pause.Visible = crosshair.Visible;
			crosshair.Visible = !crosshair.Visible;
			options.Visible = false;
			if (crosshair.Visible)
			{
				Input.MouseMode = Input.MouseModeEnum.Captured;
			}
			else
			{
				Input.MouseMode = Input.MouseModeEnum.Visible;
			}
		}
	}

	private void OnResumePressed()
	{
		Input.MouseMode = Input.MouseModeEnum.Captured;
		crosshair.Visible = true;
		pause.Visible = false;
	}

	private void OnOptionsPressed()
	{
		options.prevMenu = pause;
		options.Visible = true;
		pause.Visible = false;
	}

	private void OnMainMenuPressed()
	{
		voxel_world.CleanUp();
		GetTree().ChangeSceneToPacked(GD.Load<PackedScene>("res://menu/main/main_menu.tscn"));
	}

	private void OnExitPressed()
	{
		voxel_world.CleanUp();
		GetTree().Quit();
	}
}
